<template>
  <div class="screen-full">
    <div v-show="!isFullscreen" @click="handleFullScreen" ref="btn" >全屏模式</div>
    <div v-show="isFullscreen" @click="handleFullScreen" class="btn">退出全屏</div>
  </div>
</template>

<script>
import screenfull from "screenfull";  //引入依赖

export default {
  name: "ScreenFull",
  data() {
    return {
      isFullscreen: false, //是否全屏
    };
  },
  created() {

  },
  mounted() {
    this.init();
  },

  beforeDestroy() {
    this.destroy();
  },

  methods: {
    handleFullScreen() {
      if (!screenfull.isEnabled) {
        this.$message.info("您的浏览器版本过低，不支持全屏浏览");
        return false;
      }
      screenfull.toggle()

    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off("change", this.change);
      }
    },
  },
};
</script>
